package com.mzpai.util.generate;

/**
 * 
 * <b>根据PO生成ServiceImpl类</b><br>
 * 
 * yanglijun 2012-11-9 下午3:45:50
 * 
 * @version 1.0.0
 * 
 */
public class GenerateServiceImpl<T> extends GenerateBase<T> {

  private static final String PACKAGE_TYPE = "service.impl";

  public GenerateServiceImpl(Class<T> clazz, String moduleName, String author) {
    super(clazz, PACKAGE_TYPE, moduleName, author);
  }

  @Override
  protected void generaeImport() {
    addImport(CLAZZ_NAME, false);
    addImport("com.mzpai.service.impl.BaseServiceImpl", false);
    addImport("com.mzpai.product.service."+clazz.getSimpleName() + "Service", false);
    addImport("com.mzpai.product.mapper."+clazz.getSimpleName() + "Mapper", false);
    addImport("org.springframework.stereotype.Service", false);
    addImport("org.slf4j.Logger", false);
    addImport("org.slf4j.LoggerFactory", false);
    addImport("org.springframework.beans.factory.annotation.Autowired", false);
  }

  @Override
  protected void generaeCalssTitle() {
    StringBuffer sb = new StringBuffer("@Service");
    sb.append(NEXT_LINE);
    sb.append("public class ");
    sb.append(clazz.getSimpleName());
    sb.append(SUFFIX);
    sb.append(" extends BaseServiceImpl<");
    sb.append(clazz.getSimpleName());
    sb.append("> implements ");
    sb.append(clazz.getSimpleName());
    sb.append("Service {");
    sb.append(NEXT_LINE);
    addClassLine(sb.toString());
  }

  @Override
  protected void generaeCalssContext() {
	  
	//  删除 
		StringBuffer sb = new StringBuffer("").append(NEXT_LINE);
		
		sb.append("	Logger logger = LoggerFactory.getLogger(").append(clazz.getSimpleName()).append(".class);").append(NEXT_LINE);
		sb.append("").append(NEXT_LINE);
		sb.append("	@Autowired ").append(NEXT_LINE);
		sb.append("	private ").append(clazz.getSimpleName()).append("Mapper ").append("mapper;").append(NEXT_LINE);
//
//		sb.append("	/** ").append(NEXT_LINE);
//		sb.append("	*").append(NEXT_LINE);
//		sb.append("	* 删除 ").append(NEXT_LINE);
//		sb.append("	* @param id").append(NEXT_LINE);
//		sb.append("	*/").append(NEXT_LINE);
//		sb.append("	@Override").append(NEXT_LINE);
//		sb.append("	public int delete(String id) throws Exception {").append(NEXT_LINE);
//		sb.append("		return mapper.delete(id);").append(NEXT_LINE);
//		sb.append("	}").append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		
//		sb.append("	/** ").append(NEXT_LINE);
//		sb.append("	*").append(NEXT_LINE);
//		sb.append("	* 保存 ").append(NEXT_LINE);
//		sb.append("	* @param target").append(NEXT_LINE);
//		sb.append("	*/").append(NEXT_LINE);
//		sb.append("	@Override").append(NEXT_LINE);
//		sb.append("	public int save(").append(clazz.getSimpleName()).append(" target) throws Exception{").append(NEXT_LINE);
//		sb.append("		return mapper.save(target);").append(NEXT_LINE);
//		sb.append("	}").append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		
//		sb.append("	/** ").append(NEXT_LINE);
//		sb.append("	*").append(NEXT_LINE);
//		sb.append("	* 修改 ").append(NEXT_LINE);
//		sb.append("	* @param target").append(NEXT_LINE);
//		sb.append("	*/").append(NEXT_LINE);
//		sb.append("	@Override").append(NEXT_LINE);
//		sb.append("	public int update(").append(clazz.getSimpleName()).append(" target) throws Exception {").append(NEXT_LINE);
//		sb.append("		return mapper.update(target);").append(NEXT_LINE);
//		sb.append("	}").append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		
//		
//		
//		sb.append("	/** ").append(NEXT_LINE);
//		sb.append("	*").append(NEXT_LINE);
//		sb.append("	* 查询 ").append(NEXT_LINE);
//		sb.append("	* @param map").append(NEXT_LINE);
//		sb.append("	* @return").append(NEXT_LINE);
//		sb.append("	*/").append(NEXT_LINE);
//		sb.append("	@Override").append(NEXT_LINE);
//		sb.append("	public PageInfo<").append(clazz.getSimpleName()).append("> getList(Map<String, Object> map, Integer pageNum, Integer pageSize) throws Exception {").append(NEXT_LINE);
//		sb.append("		PageHelper.startPage(pageNum, pageSize);").append(NEXT_LINE);
//		sb.append("		return PageUtil.toPageInfo(mapper.getList(map));").append(NEXT_LINE);
//		sb.append("	}");
//		sb.append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		
//		
//		sb.append("	/** ").append(NEXT_LINE);
//		sb.append("	*").append(NEXT_LINE);
//		sb.append("	*  根据ID，查询信息 ").append(NEXT_LINE);
//		sb.append("	* @param id").append(NEXT_LINE);
//		sb.append("	* @return").append(NEXT_LINE);
//		sb.append("	*/").append(NEXT_LINE);
//		sb.append("	@Override").append(NEXT_LINE);
//		sb.append("	public ").append(clazz.getSimpleName()).append(" queryById(String id) throws Exception {").append(NEXT_LINE);
//		sb.append("		return mapper.queryById(id);").append(NEXT_LINE);
//		sb.append("	}");
//		sb.append(NEXT_LINE);
//		sb.append(NEXT_LINE);
//		
//		
//		sb.append("	/** ").append(NEXT_LINE);
//		sb.append("	*").append(NEXT_LINE);
//		sb.append("	*  查询所有数据 ").append(NEXT_LINE);
//		sb.append("	* @param id").append(NEXT_LINE);
//		sb.append("	* @return").append(NEXT_LINE);
//		sb.append("	*/").append(NEXT_LINE);
//		sb.append("	@Override").append(NEXT_LINE);
//		sb.append("	public List<").append(clazz.getSimpleName()).append("> getList(Map<String, Object> map) throws Exception{").append(NEXT_LINE);
//		sb.append("		return mapper.getList(map);").append(NEXT_LINE);
//		sb.append("	}");
//		sb.append(NEXT_LINE);
//		sb.append(NEXT_LINE);
		
		 addClassLine(sb.toString());
  }
}
